<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import colaUser from '@/api/cola/colaUser'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()



const switchStatus = (statusValue, id, statusName) => {
  colaUser.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'cola_user',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: colaUser.getList,
  recycleApi: colaUser.getRecycleList,
  add: {
    show: true,
    api: colaUser.save,
    auth: ['cola:user:save']
  },
  edit: {
    show: true,
    api: colaUser.update,
    auth: ['cola:user:update']
  },
  delete: {
    show: true,
    api: colaUser.deletes,
    auth: ['cola:user:delete'],
    realApi: colaUser.realDeletes,
    realAuth: ['cola:user:realDeletes']
  },
  recovery: {
    show: true,
    api: colaUser.recoverys,
    auth: ['cola:user:recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "组别ID",
    dataIndex: "group_id",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入组别ID"
    }
  },
  {
    title: "昵称",
    dataIndex: "nickname",
    formType: "input",
    search: true
  },
  {
    title: "密码",
    dataIndex: "password",
    formType: "input"
  },
  {
    title: "密码盐",
    dataIndex: "salt",
    formType: "input"
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "正常",
          value: "1"
        },
        {
          label: "冻结",
          value: "0"
        }
      ],
      translation: true
    }
  },
  {
    title: "电子邮箱",
    dataIndex: "email",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "手机号",
    dataIndex: "mobile",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "头像",
    dataIndex: "avatar",
    formType: "input"
  },
  {
    title: "性别",
    dataIndex: "gender",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入性别"
    }
  },
  {
    title: "生日",
    dataIndex: "birthday",
    formType: "date",
    showTime: false
  },
  {
    title: "格言",
    dataIndex: "bio",
    formType: "input"
  },
  {
    title: "连续登录天数",
    dataIndex: "successions",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入连续登录天数"
    }
  },
  {
    title: "最大连续登录天数",
    dataIndex: "max_successions",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入最大连续登录天数"
    }
  },
  {
    title: "失败次数",
    dataIndex: "login_failure",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入失败次数"
    }
  },
  {
    title: "上次登录时间",
    dataIndex: "prev_time",
    formType: "date",
    search: true,
    showTime: true
  },
  {
    title: "登录时间",
    dataIndex: "login_time",
    formType: "date",
    showTime: true
  },
  {
    title: "登录IP",
    dataIndex: "login_ip",
    formType: "input",
    search: true
  },
  {
    title: "加入IP",
    dataIndex: "join_ip",
    formType: "input"
  },
  {
    title: "加入时间",
    dataIndex: "join_time",
    formType: "date",
    showTime: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    search: true,
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'cola:user' } </script>